package samples.d3.color 
{
	import color.HSL;
	import color.RGB;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.utils.setInterval;
	import samples.BaseSample;
	import shapes.shapes2D.Circle;
	import shapes.shapes2D.curves.Spiral;
	import shapes.shapes2D.distribution.goldenRatio.GoldenRatio;
	import shapes.shapes2D.Quad;
	
	/**
	 * @author Nicolas Barradeau
	 * http://en.nicoptere.net
	 */
	public class Color4 extends BaseSample 
	{
		
		private var hsl:HSL;
		private var hue:int = 60;
		private var angle:Number = 0;
		private var circles:Vector.<Circle>;
		
		public function Color4() 
		{
			
			hsl = new HSL( hue );
			
			this.x = sw / 2;
			this.y = sh / 2;
			//scaleX = scaleY = 2;
			var points:Vector.<Point> = Spiral.compute( 0, 0, GoldenRatio.RATIO * 100, .65, 360 );
			circles = new Vector.<Circle>();
			var radius:Number;
			
			for each( var p:Point in points ) 
			{
				radius = ( .5 + Math.cos( angle ) * .5 ) * 30;
				
				var circle:Circle = new Circle( p.x, p.y, radius );
				angle += Math.PI / 180;
				addChild( circle );
				
				hsl.hue++;
				circle.fillColor = circle.strokeColor = hsl.toHex();
				circle.draw();
				
				circles.push( circle );
				
			}
			
			interval = setInterval( update, 1 );
			
			
			
			
		}
		
		private function update():void 
		{
			var i:int;
			
			for ( i = 0; i < circles.length; i++ )
			{
				var c:Circle = circles[ i ];
				
				
				c.radius = ( .5 + Math.cos( angle ) * .5 ) * 30;
				angle += Math.PI / 180 ;
				
				c.draw();
				
			}
			//rotation += .1;
		}
		
	}

}
